<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>施工日志</title>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">施工日志</div>
		</div>
	</div>

	<div class="easyui-panel" style="width: 100%; margin: 0 auto;">
		<div style="padding: 10px 60px 20px 60px">
			<form id="ff" method="post">
				<table class="content_table" id="content_table">
				</table>
			</form>
			<div style="text-align: center; margin-top: 30px;">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">保存</a>
			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro = [[${planDaily}]];
	
	$(document).ready(function() {
		var html = "";
		html+='<tr><td style="width: 100px;">日计划内容</td>';
		html+='<td colspan="3"><input id="plan'+currentPro.id+'" class="easyui-textbox" style="width:100%;height:50px;" data-options="readonly:true,multiline:true"/></td></tr>';
		if(currentPro.report==null){
			html+='<tr class="report"><td style="width: 100px;">施工日志</td><td><input class="reportid" type="hidden" value="-1" /><input class="planid" type="hidden" value="'+currentPro.id+'" /><input id="report'+currentPro.id+'" style="height:90px;width: 100%;" class="easyui-textbox content" data-options="multiline:true" />';
			html+=' <div style="margin-top:5px;">完成百分比：<input class="easyui-textbox percent" data-options="validType:[\'number\',\'percent\']"   style="width: 50px;"/></div></td></tr>';
		}else{
			html+='<tr class="report"><td style="width: 100px;">施工日志</td><td><input class="reportid" type="hidden" value="'+currentPro.report.id+'" /><input class="planid" type="hidden" value="'+currentPro.id+'" /><input id="report'+currentPro.id+'" style="height:90px;width: 100%;" class="easyui-textbox content" data-options="required:true,multiline:true"/>';
			html+=' <div style="margin-top:5px;">完成百分比：<input class="easyui-textbox percent" data-options="readonly:true,validType:[\'number\',\'percent\']"   style="width: 50px;" value="'+currentPro.report.percent+'"/></div></td></tr>';
		}
	
		$('#content_table').append(html);
		$.parser.parse('#content_table');
		$("#plan"+currentPro.id).textbox('setValue',currentPro.content);
		if(currentPro.report!=null){
			$("#report"+currentPro.id).textbox('setValue',currentPro.report.content);
		}
	});
	
	function savePro() {
		var arr = new Array();
		$("#content_table").find(".report").each(function(i){
			var report = {};
			report.id=$(this).find(".reportid").val();
			report.plandailyid=$(this).find(".planid").val();
			report.projectitemid= currentPro.planMain.item.id;
			if(currentPro.planMain.projectitemchild != null){
				report.projectitemchildid = currentPro.planMain.projectitemchild.id;
			}
			report.content = $(this).find(".content").textbox('getValue');
			report.percent = $(this).find(".percent").val();
			report.reportdate = currentPro.plandate;
			arr.push(report);
		});
		$.ajax({
			type : 'POST',
			url : "../dailyreportSave.do?projectitemid="+currentPro.planMain.item.id,
			data : JSON.stringify(arr),
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('保存施工日志', '保存施工日志成功', 'success');
				} else {
					$.messager.alert('保存施工日志', '保存施工日志失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
</script>
<style>
.content_table {
	border: 1px solid #8DB2E3
}

.content_table td {
	height: 24px;
	padding: 5px
}

.content_table {
	width: 100%;
	border-collapse: collapse
}

.grid th {
	background: #E7F3FE;
	height: 27px;
	line-height: 27px;
	border: 1px solid #8DB2E3;
	padding-left: 5px
}

.content_table td {
	border: 1px solid #8DB2E3;
	padding-left: 5px
}
</style>

</html>